package JDBC;

import Utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 使用自定义工具类的形式创建JDBC的连接
 *
 * Utils.JDBCUtils(自定义工具类)
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2021-12-14-19:12 19:12
 */
public class JDBCDemo2 {
    public static void main(String[] args) {
        ResultSet resultSet=null;
        Statement statement=null;
        Connection connection=null;
        try {
            connection = JDBCUtils.getConnection();//创建sql的注册和连接
            String sql="select * from user";
            statement = connection.createStatement();
            resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                int id = resultSet.getInt("id");
                System.out.println("--"+id+"--");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtils.close(resultSet,statement,connection);//进行资源的关闭
        }
    }
}
